//
//  RechargeViewController.m
//  iStore
//
//  Created by Geek on 15/4/22.
//  Copyright (c) 2015年 mirrtalk. All rights reserved.
//

#import "RechargeViewController.h"
#import "RequestEngine.h"
#import <AlipaySDK/AlipaySDK.h>
#import "Order.h"
#import "DataSigner.h"
#import "Alipay.h"

@interface RechargeViewController ()
{
    NSInteger choose;
}
@end

@implementation RechargeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"充值管理";
    _moneyCost.keyboardType = UIKeyboardTypeDecimalPad;
    
    [_confirm setBackgroundImage:[UIImage imageNamed:@"Rectangle_6"] forState:UIControlStateHighlighted];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)confirmPay:(id)sender {
    
    NSString *money = _moneyCost.text;
//    if ([money intValue] < 100) {
//        alert(@"100块都不给我？不可以！")
//        return;
//    }
    

    NSString *userID = [[NSUserDefaults standardUserDefaults]objectForKey:kUserId];
    NSDictionary *dict = @{@"userID":userID,@"money":money};
    if (choose == 1 && [money isEqualToString:@""] == false) {
        Alipay *alipay =[[Alipay alloc]init];
        [self activityStart];
        [RequestEngine userAliPayWithDic:dict completed:^(NSString *errorcode, NSDictionary *resultDict) {
            [self activityStop];
            if ([errorcode isEqualToString:@"0"]) {
                [alipay alipay:resultDict];
            }
            else{
                alert(@"请求服务器失败");
            }
        }];
        
        
    }
    else if(choose == 2 && [money isEqualToString:@""] == false){
        //        [RequestEngine userWechatPayWithDic:dict completed:^(NSString *errorcode, NSDictionary *resultDict) {
        //            NSLog(@"%@",errorcode);
        //           if ([errorcode isEqualToString:@"0"]) {
        //                [self alipay:resultDict];
        //            }
        //        }];
    }
    else{
        if ([money isEqualToString:@""]) {
            alert(@"请输入充值金额");
        }
        else{
            alert(@"请选择一种充值方式");
        }
    }
}
- (IBAction)buttonClick:(UIButton *)sender {
   
    if (sender.tag == 101 || sender.tag == 102) {
        _myAlipay.selected=YES;
        _myWechatPay.selected=NO;
        [_myAlipay setBackgroundImage:[UIImage imageNamed:@"Check-box.png"] forState:UIControlStateSelected];
        choose = 1;
    }
    else if(sender.tag == 103 || sender.tag == 104){
        _myWechatPay.selected=YES;
        _myAlipay.selected=NO;
        [_myWechatPay setBackgroundImage:[UIImage imageNamed:@"Check-box.png"] forState:UIControlStateSelected];
        choose = 2;
    }
}

@end

